package com.platform.core.web.controller;

import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import com.platform.core.entity.CdDictManageEntity;
import com.platform.core.service.CdDictManageBiz;
import com.platform.dto.CdDictManageDto;
import com.querydsl.core.types.Predicate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.binding.QuerydslPredicate;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;
import java.util.Map;

/**
 * Description: -字典管理接口
 *
 * @author Coder
 */
@RestController
@RequestMapping(name = "管理", path = "/management/cdDictManage")
public class CdDictManageController {

    private final CdDictManageBiz cdDictManageBiz;

    @Autowired
    public CdDictManageController(CdDictManageBiz cdDictManageBiz) {
        this.cdDictManageBiz = cdDictManageBiz;
    }

    /**
     * 分页查询数据
     */
    @PostMapping(name = "查询列表", path = "/searchList")
    public DataJsonResult<List<Map<String,String>>> searchList() {
        List<Map<String,String>> entities = cdDictManageBiz.searchList();
        return DataJsonResult.succeed(entities);
    }


    /**
    * 查询信息项列表
    */
    @PostMapping(name = "查询明细", path = "/searchDictList")
    public DataJsonResult<List<CdDictManageDto>> searchDictList(@RequestBody Map<String,String> params) {
        return DataJsonResult.succeed(cdDictManageBiz.detail(params));
    }



    /**
     * 查询信息项列表
     */
    @PostMapping(name = "查询明细", path = "/commonDict")
    public DataJsonResult<Map<String,List<Map<String,String>>> > commonDict() {
        return DataJsonResult.succeed(cdDictManageBiz.commonDict());
    }


    /**
    * 新增
    */
    @PostMapping(name = "新增", path = "/create")
    public JsonResult create(@RequestBody CdDictManageDto req) {
        cdDictManageBiz.add(req);
        return JsonResult.success();
    }

    /**
    * 修改数据
    */
    @PostMapping(name = "修改", path = "/modify")
    public JsonResult modifyCdDictManage(@RequestBody CdDictManageDto req) {
        cdDictManageBiz.modify(req);
        return JsonResult.success();
    }

    /**
    * 删除
    */
    @PostMapping(name = "删除", path = "/remove")
    public JsonResult remove(@RequestBody CdDictManageDto req) {
        cdDictManageBiz.remove(req.getId());
        return JsonResult.success();
    }
}
